<script>

const climbing = n => {
    if(n===1) return 1
    if(n===2) return 2
    return climbing(n-1) + climbing(n-2)
}

//优化
const climbing2 = n => {
    let array = []
    const step = n => {
        if(n===1) return 1
        if(n===2) return 2
        if(!array[n]){
            array[n] = step(n - 1) + step(n - 2)
        }
        return array[n]
    }
    return step(n)
}

//优化2 循环方式
const climbing3 = n => {
    let array = [, 1, 2]
    for(let i=3; i<=n; i++){
        array[i] = array[i-1] + array[i-2]
    }
    return array[n]
}


</script>